package com.zjhuang.mybatis_demo.service.Impl;

import com.zjhuang.mybatis_demo.dao.UserDao;
import com.zjhuang.mybatis_demo.entity.User;
import com.zjhuang.mybatis_demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author huang
 */
@Service("UserService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    @Transactional
    public List<User> getAll() {
        return userDao.selectAll();
    }

    @Override
    @Transactional
    public int addUser(User user) {
        return userDao.insertUser(user);
    }

    @Override
    @Transactional
    public User getById(int id) {
        return userDao.selectById(id);
    }

    @Override
    @Transactional
    public User getByName(String name) {
        return userDao.selectByName(name);
    }

    @Override
    @Transactional
    public User checkLogin(User user) {
        String name = user.getName();
        String password = user.getPassword();
        return userDao.checkLogin(name,password);
    }
}
